from queue import Queue
from threading import Thread
import time
#创建一个生产类
class Producer(Thread):
    def __init__(self,name,queue):
        Thread.__init__(self,name=name)
        self.queue=queue
    def run(self):
        for _ in range(6):
            print(f'{self.name}将产品{_}放入队列')
            self.queue.put(_)
            time.sleep(1)
        print('生产者完成了数据的存放')

class Comsumer(Thread):
    def __init__(self,name,queue):
        Thread.__init__(self,name=name)
        self.queue=queue
    def run(self):
        for _ in range(5):
            value=self.queue.get()
            print(f'消费者线程{self.name}取出了{value}')
            time.sleep(1)
        print('-'*10+'消费完成了数据的读取'+'-'*10)

if __name__ == '__main__':
    q=Queue()
    p=Producer('Producer',q)
    c=Comsumer('Comsumer',q)

    p.start()
    c.start()

    p.join()
    c.join()
    print('主程序执行完成')

    



